#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int big(int a)
{
    int sum = 0;
    int k = a;
    do {
        while (k)
        {
            sum += k % 10;
            k /= 10;
        }
        k = sum;
    } while (k >= 10);
    return k;
}

int main()
{
    int a = 0;
    scanf("%d", &a);
    printf("%d", big(a));
    return 0;
}